 def is_prime(number):
    if number <= 1:
        return False
    for i in range(2, int(number**0.5) + 1):
        if number % i == 0:
            return False
    return True

def next_prime(number):
    while True:
        number += 1
        if is_prime(number):
            return number

def main(words):
    num_word = {"zero": "0", "one": "1", "two": "2", "three": "3", "four": "4", "five": "5", "six": "6", "seven": "7", "eight": "8", "nine": "9"}
    try:
        num_str = ''.join(num_word[word] for word in words.split())
        if len(num_str) == 3:
            number = int(num_str)
            closest_prime = number if is_prime(number) else next_prime(number)
            while True:
                prev_number = number - 1
                if prev_number > 1 and is_prime(prev_number):
                    print(prev_number)
                    break
                if is_prime(closest_prime):
                    print(closest_prime)
                    break
                closest_prime += 1
                number -= 1
        else:
            print("Wrong input")
    except KeyError:
        print("Wrong input")


main(input())

